//package com.gxa.autoparts.admin.listener;
//
//import com.gxa.autoparts.core.util.JsonUtil;
//import com.rabbitmq.client.Channel;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
//import org.springframework.stereotype.Component;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author R
// * @data 2022-01-07 9:58
// */
//@Component
//public class TopicManReceiver implements ChannelAwareMessageListener {
//    @Override
//    public void onMessage(Message message, Channel channel) throws Exception {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//            //因为传递消息的时候用的map传递,所以将Map从Message内取出需要做些处理
//            String msg = message.toString();
//            String[] msgArray = msg.split("'");//可以点进Message里面看源码,单引号直接的数据就是我们的map消息数据
////            Map<String, String> msgMap = mapStringToMap(msgArray[1].trim(),3);
//            System.out.println(msgArray[1].trim());
//            String trim = msgArray[1].trim();
//            Map map = JsonUtil.readToObject(trim, Map.class);
//            Object messageId = map.get("messageId");
//            if (messageId.equals("1")){
//                System.out.println("签收成功");
//                channel.basicAck(deliveryTag,true);
//            }
////            String messageId=msgMap.get("messageId");
////            String messageData=msgMap.get("messageData");
////            String createTime=msgMap.get("createTime");
////            System.out.println("  MyAckReceiver  messageId:"+messageId+"  messageData:"+messageData+"  createTime:"+createTime);
////            System.out.println("消费的主题消息来自："+message.getMessageProperties().getConsumerQueue());
////            Map<String, String> msgMap = mapStringToMap(msgArray[1].trim(),3);
////            String messageId=msgMap.get("messageId");
////            String messageData=msgMap.get("messageData");
////            String createTime=msgMap.get("createTime");
////            System.out.println("  MyAckReceiver  messageId:"+messageId+"  messageData:"+messageData+"  createTime:"+createTime);
////            System.out.println("消费的主题消息来自："+message.getMessageProperties().getConsumerQueue());
////            System.out.println(msg);
//             //第二个参数，手动确认可以被批处理，当该参数为 true 时，则可以一次性确认 delivery_tag 小于等于传入值的所有消息
////			channel.basicReject(deliveryTag, true);//第二个参数，true会重新放回队列，所以需要自己根据业务逻辑判断什么时候使用拒绝
//        } catch (Exception e) {
//            channel.basicReject(deliveryTag, false);
//            e.printStackTrace();
//        }
//    }
//
////    @RabbitHandler
////    @RabbitListener(queues = "topic.man")
////    public void process(Map testMessage) {
////        System.out.println("TopicManReceiver消费者收到消息  : " + testMessage.toString());
////    }
//
//    //{key=value,key=value,key=value} 格式转换成map
//    private Map<String, String> mapStringToMap(String str,int entryNum ) {
//        str = str.substring(1, str.length() - 1);
//        String[] strs = str.split(",",entryNum);
//        Map<String, String> map = new HashMap<String, String>();
//        for (String string : strs) {
//            String key = string.split("=")[0].trim();
//            String value = string.split("=")[1];
//            map.put(key, value);
//        }
//        return map;
//    }
//
//}
